package com.exam.controller;

import com.exam.entity.JudgmentQuestions;
import com.exam.entity.ShortAnswerQuestions;
import com.exam.entity.common.ResponseResult;
import com.exam.service.ShortAnswerQService;
import com.exam.util.JsonUtils;
import com.exam.util.TimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class ShortAnswerQController {

    @Autowired
    @Qualifier("shortAnswerQServiceImpl")
    private ShortAnswerQService shortAnswerQService;
    ResponseResult responseResult=new ResponseResult();


    @RequestMapping("/add_short_answer_question")
    @ResponseBody
    public String add_short_answer_question(ShortAnswerQuestions shortAnswerQuestions){
        shortAnswerQuestions.setSa_creat_time(TimeUtils.getTime());
        int i = shortAnswerQService.add_short_answer_question(shortAnswerQuestions);
        if (i==1){
            responseResult.setCode(200);
            responseResult.setMessage("添加成功");
        }else {
            responseResult.setCode(0);
            responseResult.setMessage("添加失败");
        }
        return JsonUtils.getJson(responseResult);
    }


    @RequestMapping("/get_short_answerQ_by_s_id")
    @ResponseBody
    public String get_short_answerQ_by_s_id(int s_id){
        List<ShortAnswerQuestions> shortAnswerQBySId = shortAnswerQService.get_short_answerQ_by_s_id(s_id);
        responseResult.setCode(0);
        responseResult.setMessage("成功");
        responseResult.setResult(shortAnswerQBySId);
        return JsonUtils.getJson(responseResult);
    }

    @RequestMapping("/update_short_answerQ_by_sa_id")
    @ResponseBody
    public String update_judgmentQ_by_j_id(ShortAnswerQuestions shortAnswerQuestions){
        int i = shortAnswerQService.update_short_answerQ_by_sa_id(shortAnswerQuestions);
        if (i==1){
            responseResult.setCode(200);
            responseResult.setMessage("修改成功");
        }else {
            responseResult.setCode(0);
            responseResult.setMessage("修改失败");
        }
        return JsonUtils.getJson(responseResult);
    }

    @RequestMapping("/del_short_answerQ_by_sa_id")
    @ResponseBody
    public String del_short_answerQ_by_sa_id(int sa_id){
        int i = shortAnswerQService.del_short_answerQ_by_sa_id(sa_id);
        if (i==1){
            responseResult.setCode(200);
            responseResult.setMessage("删除成功");
        }else {
            responseResult.setCode(0);
            responseResult.setMessage("删除失败");
        }
        return JsonUtils.getJson(responseResult);
    }


    @RequestMapping("/get_saq_test_by_s_id")
    @ResponseBody
    public String get_saq_test_by_s_id(int s_id){
        List<ShortAnswerQuestions> saQBySId = shortAnswerQService.get_saq_test_by_s_id(s_id);
        responseResult.setCode(200);
        responseResult.setMessage("成功");
        responseResult.setResult(saQBySId);
        return JsonUtils.getJson(responseResult);
    }
}